<!DOCTYPE html>
<!-- saved from url=(0044)https://www.cnblogs.com/YatHo/p/7856556.html -->
<html lang="zh-cn"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="referrer" content="never">
<title>Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园</title>
<link type="text/css" rel="stylesheet" href="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/blog-common.css">
<link id="MainCss" type="text/css" rel="stylesheet" href="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/bundle-En_summerGarden.css">
<link id="mobile-style" media="only screen and (max-width: 767px)" type="text/css" rel="stylesheet" href="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/bundle-En_summerGarden-mobile.css">
<link title="RSS" type="application/rss+xml" rel="alternate" href="http://www.cnblogs.com/YatHo/rss">
<link title="RSD" type="application/rsd+xml" rel="EditURI" href="http://www.cnblogs.com/YatHo/rsd.xml">
<link type="application/wlwmanifest+xml" rel="wlwmanifest" href="http://www.cnblogs.com/YatHo/wlwmanifest.xml">
<script async="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/analytics.js.下载"></script><script src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/jquery-2.2.0.min.js.下载"></script>
<script type="text/javascript">var currentBlogApp = 'YatHo', cb_enable_mathjax=false;var isLogined=false;</script>
<script src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/blog-common.js.下载" type="text/javascript"></script>
</head>
<body>
<a name="top"></a>

<!--done-->
<div id="home">
<div id="header">
	<div id="blogTitle">
	<a id="lnkBlogLogo" href="http://www.cnblogs.com/YatHo/"><img id="blogLogo" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/logo.gif" alt="Return Home"></a>			
		
<!--done-->
<h1><a id="Header1_HeaderTitle" class="headermaintitle" href="http://www.cnblogs.com/YatHo/">YatHo</a></h1>
<h2></h2>



		
	</div><!--end: blogTitle 博客的标题和副标题 -->
	<div id="navigator">
		
<!--done-->
			<ul id="navList">
				<li><a id="blog_nav_sitehome" class="menu" href="http://www.cnblogs.com/">CnBlogs</a></li>
				<li><a id="blog_nav_myhome" class="menu" href="http://www.cnblogs.com/YatHo/">Home</a></li>
				<li><a id="blog_nav_newpost" class="menu" rel="nofollow" href="https://i.cnblogs.com/EditPosts.aspx?opt=1">New Post</a></li>
				<li><a id="blog_nav_contact" accesskey="9" class="menu" rel="nofollow" href="https://msg.cnblogs.com/send/YatHo">Contact</a></li>
				<li><a id="blog_nav_admin" class="menu" rel="nofollow" href="https://i.cnblogs.com/">Admin</a></li>
				<li><a id="blog_nav_rss" class="menu" href="http://www.cnblogs.com/YatHo/rss">Rss</a>
				<a id="blog_nav_rss_image" class="aHeaderXML" href="http://www.cnblogs.com/YatHo/rss"><img src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/xml.gif" alt="Rss"></a></li>
			</ul>


		<div class="blogStats">
			
			<div id="blog_stats">
<!--done-->
Posts - 216&nbsp;
Articles - 3&nbsp;
Comments - 7&nbsp;
</div>
			
		</div><!--end: blogStats -->
	</div><!--end: navigator 博客导航栏 -->
</div><!--end: header 头部 -->

<div id="main">
	<div id="mainContent">
	<div class="forFlow">
		
<div id="post_detail">
<!--done-->
<div id="topics">
	<div class="post">
		<h1 class="postTitle">
			<a id="cb_post_title_url" class="postTitle2" href="https://www.cnblogs.com/YatHo/p/7856556.html">Jenkins pipeline：pipeline 使用之语法详解</a>
		</h1>
		<div class="clear"></div>
		<div class="postBody">
			<div id="cnblogs_post_body" class="blogpost-body"><h2 id="一、引言">一、引言</h2>
<p>　　Jenkins 2.0的到来，pipline进入了视野，jenkins2.0的核心特性. 也是最适合持续交付的feature。</p>
<p>　　简单的来说，就是把Jenkins1.0版本中，Project中的相关配置信息，如SVN/Git的配置，Parameter的配置等都变成Code，即Pipeline as Code。</p>
<p>　　随着pipeline交付流水线在团队中的推广，使用pipeline脚本的job也迅速增加。</p>
<p>　　　　优势：</p>
<ul>
<li style="list-style-type: none">
<ul>
<li>　　　　通过写代码的形式配置Project，且Jenkins中内置了常用的steps。</li>
<li>　　　　实现了构建步骤代码化、构建过程视图化。</li>
</ul>
</li>
</ul>
<h2 id="二、语法简介">二、语法简介</h2>
<p>　　Pipeline最基本的部分是“step”。基本上，step告诉Jenkins 要做什么，并且作为Declarative Pipeline和Scripted Pipeline语法的基本构建块。&nbsp;<br>　　Pipeline支持两种语法：Declarative Pipeline（在Pipeline 2.5中引入，结构化方式）和Scripted Pipeline，两者都支持建立连续输送的Pipeline。</p>
<h3 id="选择Declarative Pipeline还是Scripted Pipeline">选择Declarative Pipeline还是Scripted Pipeline</h3>
<p>　　最开始的Pipeline plugin，支持的只有一种脚本类型，就是Scripted Pipeline；<br>　　Declarative Pipeline为Pipeline plugin在2.5版本之后新增的一种脚本类型，与原先的Scripted Pipeline一样，都可以用来编写脚本。</p>
<p>　　相关资料：</p>
<p>　　<a href="https://stackoverflow.com/questions/43484979/jenkins-scripted-pipeline-or-declarative-pipeline" rel="nofollow" target="_blank">https://stackoverflow.com/questions/43484979/jenkins-scripted-pipeline-or-declarative-pipeline</a><br><a href="http://jenkins-ci.361315.n4.nabble.com/Declarative-pipelines-vs-scripted-td4891792.html" rel="nofollow" target="_blank">　　http://jenkins-ci.361315.n4.nabble.com/Declarative-pipelines-vs-scripted-td4891792.html</a></p>
<p>　　从检索的资料来看，Declarative Pipeline&nbsp;是后续Open Blue Ocean所支持的类型。相对而言，Declarative Pipeline比较简单，Declarative Pipeline中，也是可以内嵌Scripted Pipeline代码的。</p>
<p>　　为与BlueOcean脚本编辑器兼容，通常建议使用Declarative Pipeline的方式进行编写,从jenkins社区的动向来看，很明显这种语法结构也会是未来的趋势。</p>
<h2 id="三、Declarative Pipeline">三、Declarative Pipeline</h2>
<p>Declarative Pipeline是Jenkins Pipeline 的一个相对较新的补充， 它在Pipeline子系统之上提出了一种更为简化和有意义的语法。<br>所有有效的Declarative Pipeline必须包含在一个pipeline块内，例如：<br>pipeline { /* insert Declarative Pipeline here */ }<br>Declarative Pipeline中的基本语句和表达式遵循与Groovy语法相同的规则 ，但有以下例外：</p>
<ul>
<li>　　a.Pipeline的顶层必须是块，具体来说是：pipeline { }</li>
<li>　　b.没有分号作为语句分隔符。每个声明必须在自己的一行</li>
<li>　　c.块只能包含Sections, Directives, Steps或赋值语句。</li>
<li>　　d.属性引用语句被视为无参方法调用。所以例如，输入被视为input（）</li>





</ul>
<h3 id="1.Sections（章节）">1.Sections（章节）</h3>
<p>　　Declarative Pipeline里的Sections通常包含一个或多个Directives或 Steps</p>
<h4 id="agent">agent</h4>
<p>　　agent部分指定整个Pipeline或特定阶段将在Jenkins环境中执行的位置，具体取决于该agent 部分的放置位置。该部分必须在pipeline块内的顶层定义 ，但stage级使用是可选的。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/b4ca18e6-8aa8-44a1-a420-cd055dbc5be6.png!large" alt=""></div>
<div class="fluidbox-wrap">　　为了支持Pipeline可能拥有的各种用例，该agent部分支持几种不同类型的参数。这些参数可以应用于pipeline块的顶层，也可以应用在每个stage指令内。</div>
<div class="fluidbox-wrap"><span style="font-weight: bold; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">参数</span></div>
<div class="fluidbox-wrap"><span style="font-weight: bold; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　</span><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">any</span></div>
<p><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　在任何可用的agent 上执行Pipeline或stage。例如：agent any</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　none</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　当在pipeline块的顶层使用none时，将不会为整个Pipeline运行分配全局agent ，每个stage部分将需要包含其自己的agent部分。</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　label</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　使用提供的label标签，在Jenkins环境中可用的代理上执行Pipeline或stage。例如：agent { label 'my-defined-label' }</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　node</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　agent { node { label 'labelName' } }，等同于 agent { label 'labelName' }，但node允许其他选项（如customWorkspace）。</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　docker</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　定义此参数时，执行Pipeline或stage时会动态供应一个docker节点去接受Docker-based的Pipelines。 docker还可以接受一个args，直接传递给docker run调用。例如：agent { docker 'maven:3-alpine' }或</span></p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_727549" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">docker</code></div><div class="line number2 index1 alt1"><code class="csharp plain">agent {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">docker {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">image </code><code class="csharp string">'maven:3-alpine'</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">label </code><code class="csharp string">'my-defined-label'</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">args&nbsp; </code><code class="csharp string">'-v /tmp:/tmp'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　<span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">dockerfile</span></p>
<p><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　使用从Dockerfile源存储库中包含的容器来构建执行Pipeline或stage 。为了使用此选项，Jenkinsfile必须从Multibranch Pipeline或“Pipeline from SCM"加载。</span><br style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px"><span style="color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; font-size: 15px; letter-spacing: 0.45px">　　　　默认是在Dockerfile源库的根目录：agent { dockerfile true }。如果Dockerfile需在另一个目录中建立，请使用以下dir选项：agent { dockerfile { dir 'someSubDir' } }。您可以通过docker build ...使用additionalBuildArgs选项，如agent { 　　　　dockerfile { additionalBuildArgs '--build-arg foo=bar' } }。</span></p>
<p>&nbsp;</p>
<p style="margin: 0px 0px 20px; font-size: 15px; line-height: 26px; color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; letter-spacing: 0.45px"><span style="font-weight: bold; color: #000000">参数</span><br>any<br>　　在任何可用的agent 上执行Pipeline或stage。例如：agent any<br>none<br>　　当在pipeline块的顶层使用none时，将不会为整个Pipeline运行分配全局agent ，每个stage部分将需要包含其自己的agent部分。<br>label<br>　　使用提供的label标签，在Jenkins环境中可用的代理上执行Pipeline或stage。例如：agent { label 'my-defined-label' }<br>node<br>　　agent { node { label 'labelName' } }，等同于 agent { label 'labelName' }，但node允许其他选项（如customWorkspace）。<br>docker<br>　　定义此参数时，执行Pipeline或stage时会动态供应一个docker节点去接受Docker-based的Pipelines。 docker还可以接受一个args，直接传递给docker run调用。例如：agent { docker 'maven:3-alpine' }或</p>
<pre class="highlight shell"><code style="font-family: Menlo, Monaco, Consolas, &quot;Courier New&quot;, monospace; white-space: pre-wrap; display: block; margin: 2px; line-height: 18px; padding: 0px !important; border: none !important">docker
agent <span class="o" style="color: #666666">{</span>
    docker <span class="o" style="color: #666666">{</span>
        image <span class="s1" style="color: #bb4444">'maven:3-alpine'</span>
        label <span class="s1" style="color: #bb4444">'my-defined-label'</span>
        args  <span class="s1" style="color: #bb4444">'-v /tmp:/tmp'</span>
    <span class="o" style="color: #666666">}</span>
<span class="o" style="color: #666666">}</span>
</code></pre>
<p style="margin: 0px 0px 20px; font-size: 15px; line-height: 26px; color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; letter-spacing: 0.45px">dockerfile<br>使用从Dockerfile源存储库中包含的容器来构建执行Pipeline或stage 。为了使用此选项，Jenkinsfile必须从Multibranch Pipeline或“Pipeline from SCM"加载。<br>默认是在Dockerfile源库的根目录：agent { dockerfile true }。如果Dockerfile需在另一个目录中建立，请使用以下dir选项：agent { dockerfile { dir 'someSubDir' } }。您可以通过docker build ...使用additionalBuildArgs选项，如agent { dockerfile { additionalBuildArgs '--build-arg foo=bar' } }。</p>
<h3 style="margin: 0px 0px 20px; font-size: 15px; line-height: 26px; color: #222527; font-family: Helvetica, Arial, &quot;PingFang SC&quot;, &quot;Noto Sans&quot;, Roboto, &quot;Microsoft Yahei&quot;, sans-serif; letter-spacing: 0.45px">常用选项</h3>
<p>这些是可以应用于两个或多个agent的选项。除非明确定义，否则不需要。<br>　　label<br>　　　　一个字符串。标记在哪里运行pipeline或stage<br>　　　　此选项适用于node，docker和dockerfile，并且 node是必需的。<br>　　customWorkspace<br>　　　　一个字符串。自定义运行的工作空间内。它可以是相对路径，在这种情况下，自定义工作区将位于节点上的工作空间根目录下，也可以是绝对路径。例如：</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_931491" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">agent {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">node {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">label </code><code class="csharp string">'my-defined-label'</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">customWorkspace </code><code class="csharp string">'/some/other/path'</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　reuseNode<br>　　　　一个布尔值，默认为false。如果为true，则在同一工作空间中。<br>　　　　此选项适用于docker和dockerfile，并且仅在 individual stage中使用agent才有效。</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_959356" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">//Execute all the steps defined in this Pipeline within a newly created container of the given name and tag (maven:3-alpine).</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent { docker </code><code class="csharp string">'maven:3-alpine'</code> <code class="csharp plain">} </code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example Build'</code><code class="csharp plain">) {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'mvn -B clean verify'</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_143075" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent none </code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example Build'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent { docker </code><code class="csharp string">'maven:3-alpine'</code> <code class="csharp plain">} </code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello, Maven'</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'mvn --version'</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example Test'</code><code class="csharp plain">) {</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent { docker </code><code class="csharp string">'openjdk:8-jre'</code> <code class="csharp plain">} </code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello, JDK'</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'java -version'</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number19 index18 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h4 id="post">post</h4>
<p>　　定义Pipeline或stage运行结束时的操作。post-condition块支持post部件：always，changed，failure，success，unstable，和aborted。这些块允许在Pipeline或stage运行结束时执行步骤，具体取决于Pipeline的状态。</p>
<p>　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/d0548c42-0ee4-435c-844d-fc9969735cc8.png!large" alt=""></p>
<p>　　conditions项：<br>　　always<br>　　　　运行，无论Pipeline运行的完成状态如何。<br>　　changed<br>　　　　只有当前Pipeline运行的状态与先前完成的Pipeline的状态不同时，才能运行。<br>　　failure<br>　　　　仅当当前Pipeline处于“失败”状态时才运行，通常在Web UI中用红色指示表示。<br>　　success<br>　　　　仅当当前Pipeline具有“成功”状态时才运行，通常在具有蓝色或绿色指示的Web UI中表示。<br>　　unstable<br>　　　　只有当前Pipeline具有“不稳定”状态，通常由测试失败，代码违例等引起，才能运行。通常在具有黄色指示的Web UI中表示。<br>　　aborted<br>　　　　只有当前Pipeline处于“中止”状态时，才会运行，通常是由于Pipeline被手动中止。通常在具有灰色指示的Web UI中表示。</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_294173" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">post { </code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">always { </code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'I will always say Hello again!'</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="stages">stages</h4>
<p>　　包含一个或多个stage的序列，Pipeline的大部分工作在此执行。建议stages至少包含至少一个stage指令，用于连接各个交付过程，如构建，测试和部署等。<br>　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/be8f539b-1b8e-41c4-9ea9-a909041385a3.png!large" alt=""></p>
<h4 id="steps">steps</h4>
<p>　　steps包含一个或多个在stage块中执行的step序列。<br>　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/19f88fdb-c8fa-448b-8a2f-0f8c2e73c746.png!large" alt=""></p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_920734" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages { </code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h3 id="2.Directives （指令）">2.Directives （指令）</h3>
<h4 id="environment">　　environment</h4>
<p>environment指令指定一系列键值对，这些键值对将被定义为所有step或stage-specific step的环境变量，具体取决于environment指令在Pipeline中的位置。<br>该指令支持一种特殊的方法credentials()，可以通过其在Jenkins环境中的标识符来访问预定义的凭据。<br>对于类型为“Secret Text”的凭据，该 credentials()方法将确保指定的环境变量包含Secret Text内容；对于“标准用户名和密码”类型的凭证，指定的环境变量将被设置为username:password。<br>　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/61e1a1c8-ccaf-4e17-95a2-cf0fc874befb.png!large" alt=""></p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_101272" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">environment { </code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">CC = </code><code class="csharp string">'clang'</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">environment { </code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">AN_ACCESS_KEY = credentials(</code><code class="csharp string">'my-prefined-secret-text'</code><code class="csharp plain">) </code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'printenv'</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h4 id="options">options</h4>
<p>options指令允许在Pipeline本身内配置Pipeline专用选项。Pipeline本身提供了许多选项，例如buildDiscarder，但它们也可能由插件提供，例如 timestamps。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/62df009a-9155-4db0-b164-2cda48a08b81.png!large" alt=""></div>
<div class="fluidbox-wrap"><strong>可用选项</strong></div>
<div class="fluidbox-wrap">
<p>　　buildDiscarder<br>　　　　pipeline保持构建的最大个数。例如：options { buildDiscarder(logRotator(numToKeepStr: '1')) }<br>　　disableConcurrentBuilds<br>　　　　不允许并行执行Pipeline,可用于防止同时访问共享资源等。例如：options { disableConcurrentBuilds() }<br>　　skipDefaultCheckout<br>　　　　默认跳过来自源代码控制的代码。例如：options { skipDefaultCheckout() }<br>　　skipStagesAfterUnstable<br>　　　　一旦构建状态进入了“Unstable”状态，就跳过此stage。例如：options { skipStagesAfterUnstable() }<br>　　timeout<br>　　　　设置Pipeline运行的超时时间。例如：options { timeout(time: 1, unit: 'HOURS') }<br>　　retry<br>　　　　失败后，重试整个Pipeline的次数。例如：options { retry(3) }<br>　　timestamps<br>　　　　预定义由Pipeline生成的所有控制台输出时间。例如：options { timestamps() }</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_5992" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">options {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">timeout(time: 1, unit: </code><code class="csharp string">'HOURS'</code><code class="csharp plain">) </code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}　</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="parameters">parameters</h4>
</div>
<p>parameters指令提供用户在触发Pipeline时的参数列表。这些参数值通过该params对象可用于Pipeline步骤，具体用法如下</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/a063f9e2-a6c6-41ea-b121-e1fc99acb112.png!large" alt=""></div>
<p><strong>可用参数</strong><br>　　string<br>　　　　A parameter of a string type, for example: parameters { string(name: 'DEPLOY_ENV', defaultValue: 'staging', description: '') }<br>　　booleanParam<br>　　　　A boolean parameter, for example: parameters { booleanParam(name: 'DEBUG_BUILD', defaultValue: true, description: '') }<br>　　目前只支持[booleanParam, choice, credentials, file, text, password, run, string]这几种参数类型，其他高级参数化类型还需等待社区支持。</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_545544" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">parameters {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">string</code><code class="csharp plain">(name: </code><code class="csharp string">'PERSON'</code><code class="csharp plain">, defaultValue: </code><code class="csharp string">'Mr Jenkins'</code><code class="csharp plain">, description: </code><code class="csharp string">'Who should I say hello to?'</code><code class="csharp plain">)</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">"Hello ${params.PERSON}"</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="triggers">triggers</h4>
<p>triggers指令定义了Pipeline自动化触发的方式。对于与源代码集成的Pipeline，如GitHub或BitBucket，triggers可能不需要基于webhook的集成也已经存在。目前只有两个可用的触发器：cron和pollSCM。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/763dc697-6402-47a2-b90c-77453ad89b88.png!large" alt=""></div>
<div class="fluidbox-wrap">cron<br>　　接受一个cron风格的字符串来定义Pipeline触发的常规间隔，例如： triggers { cron('H 4/* 0 0 1-5') }<br>pollSCM<br>　　接受一个cron风格的字符串来定义Jenkins检查SCM源更改的常规间隔。如果存在新的更改，则Pipeline将被重新触发。例如：triggers { pollSCM('H 4/* 0 0 1-5') }</div>
<div class="fluidbox-wrap">
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_186141" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">triggers {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">cron(</code><code class="csharp string">'H 4/* 0 0 1-5'</code><code class="csharp plain">)</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="stage">stage</h4>
</div>
<p>&nbsp;stage指令在stages部分中，应包含stop部分，可选agent部分或其他特定于stage的指令。实际上，Pipeline完成的所有实际工作都将包含在一个或多个stage指令中。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/3bdce47e-87af-4264-8c9d-68f27cdf816c.png!large" alt=""></div>
<div class="fluidbox-wrap">
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_414163" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}　</code></div></div></td></tr></tbody></table></div></div>
</div>
<h4 id="tools">tools</h4>
</div>
<p>&nbsp;通过tools可自动安装工具，并放置环境变量到PATH。如果agent none，这将被忽略。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/027fa60d-c999-477c-a333-172f92ec5f91.png!large" alt=""></div>
<div class="fluidbox-wrap"><strong>Supported Tools(<a class=" " href="http://192.168.1.91:8080/jenkins/configureTools">Global Tool Configuration</a>)</strong><br>　　maven<br>　　jdk<br>　　gradle</div>
<p>&nbsp;</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_152279" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">tools {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp comments">//工具名称必须在Jenkins 管理Jenkins → 全局工具配置中预配置。</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">maven </code><code class="csharp string">'apache-maven-3.0.1'</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'mvn --version'</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number14 index13 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h4 id="when">when</h4>
<p>　　when指令允许Pipeline根据给定的条件确定是否执行该阶段。该when指令必须至少包含一个条件。如果when指令包含多个条件，则所有子条件必须为stage执行返回true。这与子条件嵌套在一个allOf条件中相同（见下面的例子）。<br>更复杂的条件结构可使用嵌套条件建：not，allOf或anyOf。嵌套条件可以嵌套到任意深度。</p>
<div class="fluidbox-wrap">　　<img title="" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/e9d5d0eb-9855-4a72-a4a6-56c1fde975de.png!large" alt=""></div>
<div class="fluidbox-wrap"><strong>　　内置条件<br></strong></div>
<div class="fluidbox-wrap">　　branch<br>　　　　当正在构建的分支与给出的分支模式匹配时执行，例如：when { branch 'master' }。请注意，这仅适用于多分支Pipeline。<br>　　environment<br>　　　　当指定的环境变量设置为给定值时执行，例如： when { environment name: 'DEPLOY_TO', value: 'production' }<br>　　expression<br>　　　　当指定的Groovy表达式求值为true时执行，例如： when { expression { return params.DEBUG_BUILD } }<br>　　not<br>　　　　当嵌套条件为false时执行。必须包含一个条件。例如：when { not { branch 'master' } }<br>　　allOf<br>　　　　当所有嵌套条件都为真时执行。必须至少包含一个条件。例如：when { allOf { branch 'master'; environment name: 'DEPLOY_TO', value: 'production' } }<br>　　anyOf<br>　　　　当至少一个嵌套条件为真时执行。必须至少包含一个条件。例如：when { anyOf { branch 'master'; branch 'staging' } }</div>
<p>&nbsp;</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_224769" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example Build'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example Deploy'</code><code class="csharp plain">) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">when {</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">allOf {</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">branch </code><code class="csharp string">'production'</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">environment name: </code><code class="csharp string">'DEPLOY_TO'</code><code class="csharp plain">, value: </code><code class="csharp string">'production'</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Deploying'</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h3 id="3.Parallel(并行)">3.Parallel(并行)</h3>
<p>Declarative Pipeline近期新增了对并行嵌套stage的支持，对耗时长，相互不存在依赖的stage可以使用此方式提升运行效率。除了parallel stage，单个parallel里的多个step也可以使用并行的方式运行。</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_239614" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div><div class="line number18 index17 alt1">18</div><div class="line number19 index18 alt2">19</div><div class="line number20 index19 alt1">20</div><div class="line number21 index20 alt2">21</div><div class="line number22 index21 alt1">22</div><div class="line number23 index22 alt2">23</div><div class="line number24 index23 alt1">24</div><div class="line number25 index24 alt2">25</div><div class="line number26 index25 alt1">26</div><div class="line number27 index26 alt2">27</div><div class="line number28 index27 alt1">28</div><div class="line number29 index28 alt2">29</div><div class="line number30 index29 alt1">30</div><div class="line number31 index30 alt2">31</div><div class="line number32 index31 alt1">32</div><div class="line number33 index32 alt2">33</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Non-Parallel Stage'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'This stage will be executed first.'</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Parallel Stage'</code><code class="csharp plain">) {</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">when {</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">branch </code><code class="csharp string">'master'</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">parallel {</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Branch A'</code><code class="csharp plain">) {</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent {</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">label </code><code class="csharp string">"for-branch-a"</code></div><div class="line number17 index16 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number18 index17 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number19 index18 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">"On Branch A"</code></div><div class="line number20 index19 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number21 index20 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number22 index21 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Branch B'</code><code class="csharp plain">) {</code></div><div class="line number23 index22 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent {</code></div><div class="line number24 index23 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">label </code><code class="csharp string">"for-branch-b"</code></div><div class="line number25 index24 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number26 index25 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number27 index26 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">"On Branch B"</code></div><div class="line number28 index27 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number29 index28 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number30 index29 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number31 index30 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number32 index31 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number33 index32 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h3 id="4.Steps（步骤）">4.Steps（步骤）</h3>
<p>Declarative Pipeline可以使用 Pipeline Steps reference中的所有可用步骤 ，并附加以下仅在Declarative Pipeline中支持的步骤。</p>
<h4 id="script">script</h4>
<p>script步骤需要一个script Pipeline，并在Declarative Pipeline中执行。对于大多数用例，script在Declarative Pipeline中的步骤不是必须的，但它可以提供一个有用的加强。</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_184027" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div><div class="line number13 index12 alt2">13</div><div class="line number14 index13 alt1">14</div><div class="line number15 index14 alt2">15</div><div class="line number16 index15 alt1">16</div><div class="line number17 index16 alt2">17</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">pipeline {</code></div><div class="line number2 index1 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">agent any</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stages {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">steps {</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Hello World'</code></div><div class="line number7 index6 alt2">&nbsp;</div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">script {</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">def browsers = [</code><code class="csharp string">'chrome'</code><code class="csharp plain">, </code><code class="csharp string">'firefox'</code><code class="csharp plain">]</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">for</code> <code class="csharp plain">(</code><code class="csharp keyword">int</code> <code class="csharp plain">i = 0; i &lt; browsers.size(); ++i) {</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">"Testing the ${browsers[i]} browser"</code></div><div class="line number12 index11 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number13 index12 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number14 index13 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number15 index14 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number16 index15 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number17 index16 alt2"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h2 id="四、Scripted Pipeline">四、Scripted Pipeline</h2>
<p>　　Groovy脚本不一定适合所有使用者，因此jenkins创建了Declarative pipeline，为编写Jenkins管道提供了一种更简单、更有主见的语法。但是不可否认，由于脚本化的pipeline是基于groovy的一种DSL语言，所以与Declarative pipeline相比为jenkins用户提供了更巨大的灵活性和可扩展性。</p>
<h3 id="1.流程控制">1.流程控制</h3>
<p>　　pipeline脚本同其它脚本语言一样，从上至下顺序执行，它的流程控制取决于Groovy表达式，如if/else条件语句，举例如下：</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_690832" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">Jenkinsfile (Scripted Pipeline)</code></div><div class="line number2 index1 alt1"><code class="csharp plain">node {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">if</code> <code class="csharp plain">(env.BRANCH_NAME == </code><code class="csharp string">'master'</code><code class="csharp plain">) {</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'I only execute on the master branch'</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">} </code><code class="csharp keyword">else</code> <code class="csharp plain">{</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'I execute elsewhere'</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number10 index9 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　pipeline脚本流程控制的另一种方式是Groovy的异常处理机制。当任何一个步骤因各种原因而出现异常时，都必须在Groovy中使用try/catch/finally语句块进行处理，举例如下：</p>
<div class="cnblogs_Highlighter sh-gutter">
<div><div id="highlighter_364514" class="syntaxhighlighter  csharp"><div class="toolbar"><span><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" class="toolbar_item command_help help">?</a></span></div><table border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="gutter"><div class="line number1 index0 alt2">1</div><div class="line number2 index1 alt1">2</div><div class="line number3 index2 alt2">3</div><div class="line number4 index3 alt1">4</div><div class="line number5 index4 alt2">5</div><div class="line number6 index5 alt1">6</div><div class="line number7 index6 alt2">7</div><div class="line number8 index7 alt1">8</div><div class="line number9 index8 alt2">9</div><div class="line number10 index9 alt1">10</div><div class="line number11 index10 alt2">11</div><div class="line number12 index11 alt1">12</div></td><td class="code"><div class="container"><div class="line number1 index0 alt2"><code class="csharp plain">Jenkinsfile (Scripted Pipeline)</code></div><div class="line number2 index1 alt1"><code class="csharp plain">node {</code></div><div class="line number3 index2 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">stage(</code><code class="csharp string">'Example'</code><code class="csharp plain">) {</code></div><div class="line number4 index3 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">try</code> <code class="csharp plain">{</code></div><div class="line number5 index4 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">sh </code><code class="csharp string">'exit 1'</code></div><div class="line number6 index5 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number7 index6 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">catch</code> <code class="csharp plain">(exc) {</code></div><div class="line number8 index7 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">echo </code><code class="csharp string">'Something failed, I should sound the klaxons!'</code></div><div class="line number9 index8 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp keyword">throw</code></div><div class="line number10 index9 alt1"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number11 index10 alt2"><code class="csharp spaces">&nbsp;&nbsp;&nbsp;&nbsp;</code><code class="csharp plain">}</code></div><div class="line number12 index11 alt1"><code class="csharp plain">}</code></div></div></td></tr></tbody></table></div></div>
</div>
<p>　　</p>
<h3 id="2.Steps">2.Steps</h3>
<p>　　pipeline最核心和基本的部分就是“step”，从根本上来说，steps作为Declarative pipeline和Scripted pipeline语法的最基本的语句构建块来告诉jenkins应该执行什么操作。<br>Scripted pipeline没有专门将steps作为它的语法的一部分来介绍，但是在Pipeline Steps reference这篇文档中对pipeline及其插件涉及的steps做了很详细的介绍。如有需要可参考jenkins官网对该部分的介绍Pipeline Steps reference</p>
<h3 id="3.Differences from plain Groovy">3.Differences from plain Groovy</h3>
<p>　　由于pipeline的一些个性化需求，比如在重新启动jenkins后要求pipeline脚本仍然可以运行，那么pipeline脚本必须将相关数据做序列化，然而这一点 Groovy并不能完美的支持，例如collection.each { item -&gt; /* perform operation */ }</p>
<h3 id="4.Declarative pipeline和Scripted pipeline的比较">4.Declarative pipeline和Scripted pipeline的比较</h3>
<p>共同点：<br>　　两者都是pipeline代码的持久实现，都能够使用pipeline内置的插件或者插件提供的steps，两者都可以利用共享库扩展。<br>区别：<br>　　两者不同之处在于语法和灵活性。Declarative pipeline对用户来说，语法更严格，有固定的组织结构，更容易生成代码段，使其成为用户更理想的选择。但是Scripted pipeline更加灵活，因为Groovy本身只能对结构和语法进行限制，对于更复杂的pipeline来说，用户可以根据自己的业务进行灵活的实现和扩展。</p></div><div id="MySignature"></div>
<div class="clear"></div>
<div id="blog_post_info_block">
<div id="BlogPostCategory">分类: <a href="http://www.cnblogs.com/YatHo/category/1073568.html" target="_blank">DevOps</a>,<a href="http://www.cnblogs.com/YatHo/category/932771.html" target="_blank">jenkins-系列丛书（准备写书）</a></div>
<div id="EntryTag"></div>
<div id="blog_post_info"><div id="green_channel">
        <a href="javascript:void(0);" id="green_channel_digg" onclick="DiggIt(7856556,cb_blogId,1);green_channel_success(this,&#39;谢谢推荐！&#39;);">好文要顶</a>
            <a id="green_channel_follow" onclick="follow(&#39;2a30c363-29a6-e611-845c-ac853d9f53ac&#39;);" href="javascript:void(0);">关注我</a>
    <a id="green_channel_favorite" onclick="AddToWz(cb_entryId);return false;" href="javascript:void(0);">收藏该文</a>
    <a id="green_channel_weibo" href="javascript:void(0);" title="分享至新浪微博" onclick="ShareToTsina()"><img src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/icon_weibo_24.png" alt=""></a>
    <a id="green_channel_wechat" href="javascript:void(0);" title="分享至微信" onclick="shareOnWechat()"><img src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/wechat.png" alt=""></a>
</div>
<div id="author_profile">
    <div id="author_profile_info" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/YatHo/" target="_blank"><img src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/sample_face.gif" class="author_avatar" alt=""></a>
        <div id="author_profile_detail" class="author_profile_info">
            <a href="http://home.cnblogs.com/u/YatHo/">YatHo</a><br>
            <a href="http://home.cnblogs.com/u/YatHo/followees">关注 - 0</a><br>
            <a href="http://home.cnblogs.com/u/YatHo/followers">粉丝 - 21</a>
        </div>
    </div>
    <div class="clear"></div>
    <div id="author_profile_honor"></div>
    <div id="author_profile_follow">
                <a href="javascript:void(0);" onclick="follow(&#39;2a30c363-29a6-e611-845c-ac853d9f53ac&#39;);return false;">+加关注</a>
    </div>
</div>
<div id="div_digg">
    <div class="diggit" onclick="votePost(7856556,&#39;Digg&#39;)">
        <span class="diggnum" id="digg_count">0</span>
    </div>
    <div class="buryit" onclick="votePost(7856556,&#39;Bury&#39;)">
        <span class="burynum" id="bury_count">0</span>
    </div>
    <div class="clear"></div>
    <div class="diggword" id="digg_tips">
    </div>
</div>
<script type="text/javascript">
    currentDiggType = 0;
</script></div>
<div class="clear"></div>
<div id="post_next_prev"><a href="http://www.cnblogs.com/YatHo/p/7852101.html" class="p_n_p_prefix">« </a> 上一篇：<a href="http://www.cnblogs.com/YatHo/p/7852101.html" title="发布于2017-11-17 16:06">Xcode脚本自动化打包问题：xcrun: error: unable to find utility "PackageApplication", not a developer tool or in PATH</a><br><a href="http://www.cnblogs.com/YatHo/p/7863067.html" class="p_n_p_prefix">» </a> 下一篇：<a href="http://www.cnblogs.com/YatHo/p/7863067.html" title="发布于2017-11-20 00:07">使用docker搭建公司redmine服务器</a><br></div>
</div>


		</div>
		<div class="postDesc">posted @ <span id="post-date">2017-11-18 14:12</span> <a href="http://www.cnblogs.com/YatHo/">YatHo</a> Views(<span id="post_view_count">2139</span>) Comments(<span id="post_comment_count">0</span>)  <a href="https://i.cnblogs.com/EditPosts.aspx?postid=7856556" rel="nofollow">Edit</a> <a href="https://www.cnblogs.com/YatHo/p/7856556.html#" onclick="AddToWz(7856556);return false;">收藏</a></div>
	</div>
	<script type="text/javascript">var allowComments=true,cb_blogId=316801,cb_entryId=7856556,cb_blogApp=currentBlogApp,cb_blogUserGuid='2a30c363-29a6-e611-845c-ac853d9f53ac',cb_entryCreatedDate='2017/11/18 14:12:00';loadViewCount(cb_entryId);var cb_postType=1;</script>
	
</div>
</div><a name="!comments"></a><div id="blog-comments-placeholder"></div><script type="text/javascript">var commentManager = new blogCommentManager();commentManager.renderComments(0);</script>
<div id="comment_form" class="commentform">
<a name="commentform"></a>
<div id="divCommentShow"></div>
<div id="comment_nav"><span id="span_refresh_tips"></span><a href="javascript:void(0);" onclick="return RefreshCommentList();" id="lnk_RefreshComments" runat="server" clientidmode="Static">刷新评论</a><a href="https://www.cnblogs.com/YatHo/p/7856556.html#" onclick="return RefreshPage();">刷新页面</a><a href="https://www.cnblogs.com/YatHo/p/7856556.html#top">返回顶部</a></div>
<div id="comment_form_container"><div class="login_tips">注册用户登录后才能发表评论，请 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return login(&#39;commentform&#39;);">登录</a> 或 <a rel="nofollow" href="javascript:void(0);" class="underline" onclick="return register();">注册</a>，<a href="http://www.cnblogs.com/">访问</a>网站首页。</div></div>
<div class="ad_text_commentbox" id="ad_text_under_commentbox"></div>
<div id="ad_t2"><a href="http://www.ucancode.com/index.htm" target="_blank">【推荐】超50万VC++源码: 大型组态工控、电力仿真CAD与GIS源码库！</a><br><a href="https://www.yunqi2050.com/" target="_blank">【活动】2050 大会 - 年青人因科技而团聚（5.26-5.27 杭州·云栖小镇）</a><br><a href="http://clickc.admaster.com.cn/c/a105960,b2436452,c1705,i0,m101,8a1,8b2,h" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-DevCloud&#39;)">【推荐】华为云7大明星产品0元免费使用</a><br><a href="https://cloud.tencent.com/product/tac?fromSource=gwzcw.926333.926333.926333" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-腾讯云&#39;)">【推荐】腾讯云如何降低移动开发成本</a><br><a href="http://challenge.xfyun.cn/?ch=bk" target="_blank" onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;T2-xfyun&#39;)">【大赛】2018首届“顶天立地”AI开发者大赛</a><br></div>
<div id="opt_under_post"></div>
<div id="cnblogs_c1" class="c_ad_block"><a onclick="ga(&#39;send&#39;, &#39;event&#39;, &#39;Link&#39;, &#39;click&#39;, &#39;C1&#39;);" href="https://cloud.tencent.com/solution/la?fromSource=gwzcw.926335.926335.926335" target="_blank"><img width="300" height="250" src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/24442-20180520213658559-918592692.jpg" alt="腾讯云0518"></a></div>
<div id="under_post_news"><div class="itnews c_ad_block"><b>最新IT新闻</b>:<br> ·  <a href="https://news.cnblogs.com/n/597456/" target="_blank">中兴通讯发布公告：A股继续停牌 控股股东增持</a><br> ·  <a href="https://news.cnblogs.com/n/597455/" target="_blank">50项技术让人延寿40年！一图看清史上最牛的发明</a><br> ·  <a href="https://news.cnblogs.com/n/597453/" target="_blank">视频揭示：艾滋病病毒如何“感染”细胞</a><br> ·  <a href="https://news.cnblogs.com/n/597452/" target="_blank">马斯克将创办新闻和记者信誉点评网站Pravda</a><br> ·  <a href="https://news.cnblogs.com/n/597454/" target="_blank">腾讯“赛马”：既当运动员又当裁判官</a><br>» <a href="http://news.cnblogs.com/" title="IT新闻" target="_blank">更多新闻...</a></div></div>
<div id="cnblogs_c2" class="c_ad_block"><a href="http://click.aliyun.com/m/34770/" target="_blank"><img src="./Jenkins pipeline：pipeline 使用之语法详解 - YatHo - 博客园_files/TB1gBPhgZLJ8KJjy0FnXXcFDpXa-468-60.jpg" alt="" style="width: 468px; height: 60px;"></a></div>
<div id="under_post_kb"><div class="itnews c_ad_block" id="kb_block"><b>最新知识库文章</b>:<br><div id="kb_recent"> ·  <a href="http://kb.cnblogs.com/page/576411/" target="_blank">你可以把编程当做一项托付终身的职业</a><br> ·  <a href="http://kb.cnblogs.com/page/596164/" target="_blank">评审的艺术——谈谈现实中的代码评审</a><br> ·  <a href="http://kb.cnblogs.com/page/577233/" target="_blank">如何高效学习</a><br> ·  <a href="http://kb.cnblogs.com/page/578689/" target="_blank">如何成为优秀的程序员？</a><br> ·  <a href="http://kb.cnblogs.com/page/594930/" target="_blank">菜鸟工程师的超神之路 -- 从校园到职场</a><br></div>» <a href="http://kb.cnblogs.com/" target="_blank">更多知识库文章...</a></div></div>
<div id="HistoryToday" class="c_ad_block"><b>历史上的今天:</b><br>2016-11-18 <a href="http://www.cnblogs.com/YatHo/p/6078322.html">基于jmeter,jenkins，ANT接口，性能测试框架</a><br>2016-11-18 <a href="http://www.cnblogs.com/YatHo/p/6077830.html">JMeterPluginsCMD Command Line Tool</a><br>2016-11-18 <a href="http://www.cnblogs.com/YatHo/p/6077445.html">jenkins - jsp或其他web样式无法展示</a><br></div>
<script type="text/javascript">
    fixPostBody();
    setTimeout(function () { incrementViewCount(cb_entryId); }, 50);
    deliverAdT2();
    deliverAdC1();
    deliverAdC2();    
    loadNewsAndKb();
    loadBlogSignature();
    LoadPostInfoBlock(cb_blogId, cb_entryId, cb_blogApp, cb_blogUserGuid);
    GetPrevNextPost(cb_entryId, cb_blogId, cb_entryCreatedDate, cb_postType);
    loadOptUnderPost();
    GetHistoryToday(cb_blogId, cb_blogApp, cb_entryCreatedDate);   
</script>
</div>


	</div><!--end: forFlow -->
	</div><!--end: mainContent 主体内容容器-->

	<div id="sideBar">
		<div id="sideBarMain">
			
<!--done-->
<div class="newsItem">
<h3 class="catListTitle">公告</h3>
	<div id="blog-news"><div id="profile_block">昵称：<a href="https://home.cnblogs.com/u/YatHo/">YatHo</a><br>园龄：<a href="https://home.cnblogs.com/u/YatHo/" title="入园时间：2016-11-09">1年6个月</a><br>粉丝：<a href="https://home.cnblogs.com/u/YatHo/followers/">21</a><br>关注：<a href="https://home.cnblogs.com/u/YatHo/followees/">0</a><div id="p_b_follow"><a href="javascript:void(0);" onclick="follow(&#39;2a30c363-29a6-e611-845c-ac853d9f53ac&#39;)">+加关注</a></div><script>getFollowStatus('2a30c363-29a6-e611-845c-ac853d9f53ac')</script></div></div><script type="text/javascript">loadBlogNews();</script>
</div>

			<div id="calendar"></div>
			
			<div id="leftcontentcontainer">
				<div id="blog-sidecolumn"><div id="sidebar_search" class="sidebar-block">
<div class="mySearch">
<h3 class="catListTitle">Search</h3>
<div id="widget_my_zzk" class="div_my_zzk"><input type="text" id="q" onkeydown="return zzk_go_enter(event);" class="input_my_zzk">&nbsp;<input onclick="zzk_go()" type="button" value="ZZK" id="btnZzk" class="btn_my_zzk"></div>
<div id="widget_my_google" class="div_my_zzk"><input type="text" name="google_q" id="google_q" onkeydown="return google_go_enter(event)" class="input_my_zzk">&nbsp;<input onclick="google_go()" type="button" value="Google" class="btn_my_zzk"></div>
</div></div><div id="sidebar_shortcut" class="sidebar-block">
<!--
<div class="catListLink">
<h3 class ="catListTitle">常用链接</h3>
<ul>
<li><a href="http://www.cnblogs.com/YatHo/p/" title="我的博客的随笔列表">我的随笔</a></li><li><a href="http://www.cnblogs.com/YatHo/MyComments.html" title="我发表过的评论列表">我的评论</a></li><li><a href="http://www.cnblogs.com/YatHo/OtherPosts.html" title="我评论过的随笔列表">我的参与</a></li><li><a href="http://www.cnblogs.com/YatHo/RecentComments.html" title="我的博客的评论列表">最新评论</a></li><li><a href="http://www.cnblogs.com/YatHo/tag/" title="我的博客的标签列表">我的标签</a></li>
<li><a id="itemListLink" onclick="this.blur();WarpClass('itemListLink', 'itemListLin_con');return false;" href="#">更多链接</a></li>
</ul>
<div id="itemListLin_con" style="display:none;">
<ul>

</ul>
</div>
</div>
--></div><div id="sidebar_toptags" class="sidebar-block">
<div class="catListTag">
<h3 class="catListTitle">My Tags</h3>
<ul>
<li><a href="http://www.cnblogs.com/YatHo/tag/jmeter/">jmeter</a>(9)</li><li><a href="http://www.cnblogs.com/YatHo/tag/jenkins/">jenkins</a>(8)</li><li><a href="http://www.cnblogs.com/YatHo/tag/%E6%8E%A5%E5%8F%A3%E6%B5%8B%E8%AF%95/">接口测试</a>(8)</li><li><a href="http://www.cnblogs.com/YatHo/tag/linux%E8%87%AA%E5%8A%A8%E5%8C%96%E9%83%A8%E7%BD%B2/">linux自动化部署</a>(7)</li><li><a href="http://www.cnblogs.com/YatHo/tag/Serv-u/">Serv-u</a>(4)</li><li><a href="http://www.cnblogs.com/YatHo/tag/maven/">maven</a>(2)</li><li><a href="http://www.cnblogs.com/YatHo/tag/Serv-u%20%E7%89%88%E6%9C%AC%E6%8E%A7%E5%88%B6/">Serv-u 版本控制</a>(2)</li><li><a href="http://www.cnblogs.com/YatHo/tag/%E7%A6%85%E9%81%93/">禅道</a>(2)</li><li><a href="http://www.cnblogs.com/YatHo/tag/%E7%A6%85%E9%81%93SQA-%E6%B5%8B%E8%AF%95%E8%BF%9B%E5%BA%A6%E8%B7%9F%E8%BF%9B/">禅道SQA-测试进度跟进</a>(1)</li><li><a href="http://www.cnblogs.com/YatHo/tag/%E9%9B%86%E7%BE%A4%E5%8E%8B%E5%8A%9B%E6%B5%8B%E8%AF%95/">集群压力测试</a>(1)</li><li><a href="http://www.cnblogs.com/YatHo/tag/">更多</a></li>
</ul>
</div></div><div id="sidebar_categories">
<div class="catListPostCategory">
<h3 class="catListTitle">Post Categories</h3>

<ul>

<li><a id="CatList_LinkList_0_Link_0" href="https://www.cnblogs.com/YatHo/category/979207.html">android(5)</a> </li>

<li><a id="CatList_LinkList_0_Link_1" href="https://www.cnblogs.com/YatHo/category/1131833.html">ansible(6)</a> </li>

<li><a id="CatList_LinkList_0_Link_2" href="https://www.cnblogs.com/YatHo/category/1145342.html">Ant(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_3" href="https://www.cnblogs.com/YatHo/category/915380.html">APP测试(8)</a> </li>

<li><a id="CatList_LinkList_0_Link_4" href="https://www.cnblogs.com/YatHo/category/1024270.html">CMD(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_5" href="https://www.cnblogs.com/YatHo/category/1073568.html">DevOps(14)</a> </li>

<li><a id="CatList_LinkList_0_Link_6" href="https://www.cnblogs.com/YatHo/category/1019113.html">Docker(36)</a> </li>

<li><a id="CatList_LinkList_0_Link_7" href="https://www.cnblogs.com/YatHo/category/914774.html">FTP服务器(12)</a> </li>

<li><a id="CatList_LinkList_0_Link_8" href="https://www.cnblogs.com/YatHo/category/932771.html">jenkins-系列丛书（准备写书）(43)</a> </li>

<li><a id="CatList_LinkList_0_Link_9" href="https://www.cnblogs.com/YatHo/category/908867.html">jmeter(5)</a> </li>

<li><a id="CatList_LinkList_0_Link_10" href="https://www.cnblogs.com/YatHo/category/957909.html">Linux(38)</a> </li>

<li><a id="CatList_LinkList_0_Link_11" href="https://www.cnblogs.com/YatHo/category/1032278.html">MAC(4)</a> </li>

<li><a id="CatList_LinkList_0_Link_12" href="https://www.cnblogs.com/YatHo/category/1022056.html">maven(15)</a> </li>

<li><a id="CatList_LinkList_0_Link_13" href="https://www.cnblogs.com/YatHo/category/1146355.html">mysql(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_14" href="https://www.cnblogs.com/YatHo/category/1022981.html">niginx(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_15" href="https://www.cnblogs.com/YatHo/category/1112518.html">PHP(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_16" href="https://www.cnblogs.com/YatHo/category/1145396.html">Python(2)</a> </li>

<li><a id="CatList_LinkList_0_Link_17" href="https://www.cnblogs.com/YatHo/category/1135569.html">redmine(6)</a> </li>

<li><a id="CatList_LinkList_0_Link_18" href="https://www.cnblogs.com/YatHo/category/1056318.html">sonar(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_19" href="https://www.cnblogs.com/YatHo/category/1033622.html">STF(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_20" href="https://www.cnblogs.com/YatHo/category/913900.html">安全(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_21" href="https://www.cnblogs.com/YatHo/category/975364.html">版本规范(4)</a> </li>

<li><a id="CatList_LinkList_0_Link_22" href="https://www.cnblogs.com/YatHo/category/1192181.html">产品管理(3)</a> </li>

<li><a id="CatList_LinkList_0_Link_23" href="https://www.cnblogs.com/YatHo/category/1151890.html">管理(4)</a> </li>

<li><a id="CatList_LinkList_0_Link_24" href="https://www.cnblogs.com/YatHo/category/1022055.html">环境更新要点记录(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_25" href="https://www.cnblogs.com/YatHo/category/1149387.html">理财</a> </li>

<li><a id="CatList_LinkList_0_Link_26" href="https://www.cnblogs.com/YatHo/category/1032145.html">软件测试(1)</a> </li>

<li><a id="CatList_LinkList_0_Link_27" href="https://www.cnblogs.com/YatHo/category/910581.html">性能测试(2)</a> </li>

<li><a id="CatList_LinkList_0_Link_28" href="https://www.cnblogs.com/YatHo/category/1150133.html">学习小计（书本，视频）(5)</a> </li>

</ul>

</div>

<div class="catListPostArchive">
<h3 class="catListTitle">Post Archives</h3>

<ul>

<li><a id="CatList_LinkList_1_Link_0" href="https://www.cnblogs.com/YatHo/archive/2018/05.html">2018/5 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_1" href="https://www.cnblogs.com/YatHo/archive/2018/04.html">2018/4 (3)</a> </li>

<li><a id="CatList_LinkList_1_Link_2" href="https://www.cnblogs.com/YatHo/archive/2018/03.html">2018/3 (5)</a> </li>

<li><a id="CatList_LinkList_1_Link_3" href="https://www.cnblogs.com/YatHo/archive/2018/01.html">2018/1 (23)</a> </li>

<li><a id="CatList_LinkList_1_Link_4" href="https://www.cnblogs.com/YatHo/archive/2017/12.html">2017/12 (12)</a> </li>

<li><a id="CatList_LinkList_1_Link_5" href="https://www.cnblogs.com/YatHo/archive/2017/11.html">2017/11 (24)</a> </li>

<li><a id="CatList_LinkList_1_Link_6" href="https://www.cnblogs.com/YatHo/archive/2017/10.html">2017/10 (15)</a> </li>

<li><a id="CatList_LinkList_1_Link_7" href="https://www.cnblogs.com/YatHo/archive/2017/09.html">2017/9 (11)</a> </li>

<li><a id="CatList_LinkList_1_Link_8" href="https://www.cnblogs.com/YatHo/archive/2017/08.html">2017/8 (4)</a> </li>

<li><a id="CatList_LinkList_1_Link_9" href="https://www.cnblogs.com/YatHo/archive/2017/07.html">2017/7 (11)</a> </li>

<li><a id="CatList_LinkList_1_Link_10" href="https://www.cnblogs.com/YatHo/archive/2017/06.html">2017/6 (21)</a> </li>

<li><a id="CatList_LinkList_1_Link_11" href="https://www.cnblogs.com/YatHo/archive/2017/05.html">2017/5 (12)</a> </li>

<li><a id="CatList_LinkList_1_Link_12" href="https://www.cnblogs.com/YatHo/archive/2017/04.html">2017/4 (17)</a> </li>

<li><a id="CatList_LinkList_1_Link_13" href="https://www.cnblogs.com/YatHo/archive/2017/03.html">2017/3 (15)</a> </li>

<li><a id="CatList_LinkList_1_Link_14" href="https://www.cnblogs.com/YatHo/archive/2017/02.html">2017/2 (1)</a> </li>

<li><a id="CatList_LinkList_1_Link_15" href="https://www.cnblogs.com/YatHo/archive/2017/01.html">2017/1 (3)</a> </li>

<li><a id="CatList_LinkList_1_Link_16" href="https://www.cnblogs.com/YatHo/archive/2016/12.html">2016/12 (6)</a> </li>

<li><a id="CatList_LinkList_1_Link_17" href="https://www.cnblogs.com/YatHo/archive/2016/11.html">2016/11 (28)</a> </li>

</ul>

</div>

<div class="catListArticleCategory">
<h3 class="catListTitle">Article Categories</h3>

<ul>

<li><a id="CatList_LinkList_2_Link_0" href="https://www.cnblogs.com/YatHo/category/908873.html">jmeter(1)</a> </li>

</ul>

</div>

</div><div id="sidebar_recentcomments" class="sidebar-block"><div id="recent_comments_wrap">
<div class="catListComment">
<h3 class="catListTitle">Recent Comments</h3>

	<div id="RecentCommentsBlock"><ul>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/YatHo/p/7100609.html#3909502">1. Re:Docker for windows10 配置镜像加速</a></li>
        <li class="recent_comment_body">管用，谢谢博主</li>
        <li class="recent_comment_author">--秋初情末</li>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/YatHo/p/6092599.html#3889045">2. Re:jmeter压力测试报告 - DEMO</a></li>
        <li class="recent_comment_body">请问这些图片是怎么得到的？比如每秒钟的响应等</li>
        <li class="recent_comment_author">--susudala</li>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/YatHo/p/6647561.html#3881238">3. Re:基于jenkins搭建一个持续集成服务器</a></li>
        <li class="recent_comment_body">写的非常详细 mark一下 能转吗</li>
        <li class="recent_comment_author">--caozengling</li>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/YatHo/p/7345077.html#3868671">4. Re:sonar-scanner扫描代码出错 SonarQube svn: E170001</a></li>
        <li class="recent_comment_body">解决了我的问题，非常感谢！以为只配置sonar.scm.disabled=true就可以了，原来还需要在server上配置</li>
        <li class="recent_comment_author">--雨vs枫</li>
        <li class="recent_comment_title"><a href="http://www.cnblogs.com/YatHo/p/6104646.html#3793329">5. Re:FTP服务器 Serv-u 环境搭建</a></li>
        <li class="recent_comment_body">厉害</li>
        <li class="recent_comment_author">--18902206676</li>
</ul>
</div>
</div>
</div></div><div id="sidebar_topviewedposts" class="sidebar-block"><div id="topview_posts_wrap">
<div class="catListView">
<h3 class="catListTitle">Top Posts</h3>
	<div id="TopViewPostsBlock"><ul><li><a href="https://www.cnblogs.com/YatHo/p/6092599.html">1. jmeter压力测试报告 - DEMO(23491)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7866029.html">2. Docker 日志都在哪里？怎么收集？(7412)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7815400.html">3. CentOS7下安装Docker-Compose(5339)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6647561.html">4. 基于jenkins搭建一个持续集成服务器(4713)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6782142.html">5. Jenkins2 插件 Pipeline+BlueOcean 实现持续交付的初次演练(2734)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7100609.html">6. Docker for windows10 配置镜像加速(2462)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7526852.html">7. Linux更换jdk版本,java -version还是原来的版本问题(2386)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6780806.html">8. jenkins2 -pipeline 常用groovy脚本(2367)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7058794.html">9. maven添加jar包依赖(2196)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7856556.html">10. Jenkins pipeline：pipeline 使用之语法详解(2139)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6140221.html">11. Chrome浏览器 54 版本显示“Adobe flash player已过期”问题解决(2021)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6492830.html">12. Windows远程linux服务器执行shell命令(1707)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6647387.html">13. SVN的目录管理规范(1685)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6492823.html">14. linux执行sh报错：$’\r’: 未找到命令的解决(1579)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6924908.html">15. *更新*无需root，一条命令强制全屏模式(1559)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6739814.html">16. 使用Publish Over SSH插件实现远程自动部署(1510)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7233194.html">17. maven-编译速度优化(1351)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/8275559.html">18. Docker Compose 版本过高（Docker版本不匹配），降低docker-compose版本(1149)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6141153.html">19. serv-u中如何映射网络驱动器(1060)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6070660.html">20. 基于Jmeter和Jenkins搭建性能测试框架(1009)</a></li></ul></div>
</div>
</div></div><div id="sidebar_topcommentedposts" class="sidebar-block"><div id="topfeedback_posts_wrap" style="display: none;">
<!--
<div class="catListFeedback">
<h3 class="catListTitle">评论排行榜</h3>
	<div id="TopFeedbackPostsBlock"></div>
</div>
-->
</div></div><div id="sidebar_topdiggedposts" class="sidebar-block"><div id="topdigg_posts_wrap">
<h3 class="catListTitle">推荐排行榜</h3>
<div class="RecentComment">
	<div id="TopDiggPostsBlock"><ul><li><a href="https://www.cnblogs.com/YatHo/p/6140221.html">1. Chrome浏览器 54 版本显示“Adobe flash player已过期”问题解决(1)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6647561.html">2. 基于jenkins搭建一个持续集成服务器(1)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/6641238.html">3. 持续集成好处(1)</a></li><li><a href="https://www.cnblogs.com/YatHo/p/7100609.html">4. Docker for windows10 配置镜像加速(1)</a></li></ul></div>
</div></div></div></div><script type="text/javascript">loadBlogSideColumn();</script>
			</div>
			
		</div><!--end: sideBarMain -->
	</div><!--end: sideBar 侧边栏容器 -->
	<div class="clear"></div>
	</div><!--end: main -->
	<div class="clear"></div>
	<div id="footer">
		
<!--done-->
Copyright ©2018 YatHo
	</div><!--end: footer -->
</div><!--end: home 自定义的最大容器 -->


</body></html>